package com.yupi.springbootinit.utils;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @CLASSNAME DateUtils
 * @USER yhl
 * @DATE 2024/3/14 15:06
 */
public class DateUtils {
    /**
     * 把date类型转换成时分秒的格式
     */
    public static String changeDateToSFM(Date date){
        LocalDateTime localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        String[] ts = localDate.toString().split("T");
        String[] split = ts[1].split("\\.");
        String s = split[0];
        return s;
    }
    public static long calculateWorkdays(LocalDate startDate, LocalDate endDate) {
        long workdays = 0;
        LocalDate date = startDate;

        while (!date.isAfter(endDate)) {
            if (date.getDayOfWeek() != DayOfWeek.SATURDAY && date.getDayOfWeek() != DayOfWeek.SUNDAY) {
                workdays++;
            }
            date = date.plusDays(1);
        }
        return workdays;
    }
}
